<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>functions</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const functions = (obj, inherited = false) =>
            (inherited
                ? [...Object.keys(obj), ...Object.keys(Object.getPrototypeOf(obj))]
                : Object.keys(obj)
            ).filter(k => typeof obj[k] === 'function');
        function Foo() {
            this.a = () => 1;
            this.b = () => 2;
        }
        Foo.prototype.c = () => 3;
        console.log(functions(new Foo())); // ['a', 'b']
        console.log(functions(new Foo(), true)); // ['a', 'b', 'c']
    </script>
</body>

</html>